'use strict'

class feedback {
  constructor() {
    this.param = '/'
  }

  async get(c) {
    let ret = await c.service.psql.query(`select * from feedback order by feedback_id asc`)
    c.status(200).send(ret.rows)
  }

  async delete(c) {
    console.log(c.body)
    if (!c.body.isRows) {
      var id = c.body.id
      console.log(id)
      if (id) {
        let ret = await c.service.psql.query(`delete from feedback where feedback_id = '${parseInt(id)}'`)
        console.log(ret)
        c.send('已删除')

      } else {
        c.send('删除失败')
      }
    } else {
      var idArr = c.body.idArr
      console.log(idArr)
      for (let i = 0; i < idArr.length; i++) {
        let ret = await c.service.psql.query(`delete from feedback where feedback_id = '${parseInt(idArr[i])}'`)
        console.log(ret)
      }
      c.send('complete')
    }
  }
}

module.exports = feedback
